﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DoAn_BumTruong_DesignPattern
{
    class ModuleController : Abstract
    {
        public List<Module> SelectAll()
        {
            using (var db = new DBContextEntity())
            {
                var query = from md in db.Modules
                            select md;
                return query.ToList();
            }
        }
        //paging
        public List<Module> Paging(string page, out int howManyPage)
        {
            int pageSize = GlobalConfiguration.PageSize;
            howManyPage = (int)Math.Ceiling((double)SelectAll().Count / (double)pageSize);
            return SelectAll().Skip(pageSize * Convert.ToInt32(page) - pageSize).Take(pageSize).ToList();
        }
        public override bool Add(object o)
        {
            throw new NotImplementedException();
        }

        public override bool Delete(object o)
        {
            throw new NotImplementedException();
        }

        public override bool Update(object o)
        {
            throw new NotImplementedException();
        }

        public override bool UpdateActive(int id, bool state)
        {
            using (var db = new DBContextEntity())
            {
                var module = db.Modules.Find(id);
                if (module != null)
                {
                    module.ModuleID = id;
                    module.Active = state;
                    db.SaveChanges();
                }
                return true;
            }
        }

        //Update Position
        public override bool UpdatePosition(int id, int position)
        {
            using (var db = new DBContextEntity())
            {
                var module = db.Modules.Find(id);
                if (module != null)
                {
                    module.ModuleID = id;
                    module.PositionDisplay = position;
                    db.SaveChanges();
                }
                return true;
            }
        }

        public override bool UpdateOrderNo(int id, int order)
        {
            throw new NotImplementedException();
        }

        public override bool UpdateMenuType(int id, int type)
        {
            throw new NotImplementedException();
        }
    }
}